<?php

namespace Vavilen\FirstBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Vavilen\FirstBundle\Entity\Category;

class DefaultController extends Controller
{
    public function indexAction()
    {
	    $em = $this->get('doctrine')->getEntityManager();
	    $posts = $em->getRepository('VavilenFirstBundle:Post')->findAll();

	    $paginator = $this->get('knp_paginator');
	    $pagination = $paginator->paginate(
		    $posts,
		    $this->get('request')->query->get('page', 1)/*page number*/,
		    2/*limit per page*/
	    );

	    $categoriesTree = $em->getRepository('VavilenFirstBundle:Category')->getCategoriesTree();

        return $this->render('VavilenFirstBundle:Default:index.html.twig', compact(
	        'test',
	        'pagination',
	        'categoriesTree'
        ));
    }
}
